<?php

class GetStatusController extends Controller {

	public function actionIndex() {
		$this->pageTitle = 'Узнать статус ремонта — Моби03';
		Yii::app()->clientScript->registerMetaTag('', 'description');
		Yii::app()->clientScript->registerMetaTag('Узнать статус ремонта', 'keywords');
		$result = array();
		$messages = array();
		$orderNo = '';
		$phone = '';
		if (isset(Yii::app()->session['statusAttributes']) && !isset($_POST['getStatusForm']))
			$_POST['getStatusForm'] = Yii::app()->session['statusAttributes'];
		if (isset($_POST['getStatusForm'])) {
			$orderNo = $_POST['getStatusForm']['orderNo'];
			$phone = $_POST['getStatusForm']['orderPhone'];
			Yii::app()->session['statusAttributes'] = $_POST['getStatusForm'];
			if (isset($_POST['getStatusForm']['orderNo']) && trim($_POST['getStatusForm']['orderNo']) != "") {
				$post = trim($_POST['getStatusForm']['orderNo']);
				$url = "http://erp.mobi03.ru/6878/requestStatus.ashx?requestNumber=" . $post . '&newResp=1';
				$result = json_decode(file_get_contents($url), true);
				$messages = json_decode(file_get_contents('http://erp.mobi03.ru/6878/requestWorks.ashx?requestNumber=' . $post), true);
			}
		}
//		echo '<pre>';
//		print_r($messages);exit;
		$model = new StatusForm();
		

		$this->render('index', array('result' => $result, 'orderNo' => $orderNo, 'phone' => $phone, 'messages' => $messages, 'model' => $model));
	}

}
